<?php

$servername = "localhost";
$username = "root";
$password = "root";

try {
  $conn = new PDO("mysql:host=$servername;dbname=dish;", $username, $password);
  echo "连接成功<br/>";
} catch (PDOException $e) {
  echo $e->getMessage();
}

$conn->exec("set names utf8;");

$sql = "select * from dish;";

$psql = $conn->prepare($sql);
$o = $psql->execute();


$all = $psql->fetchAll();

$size = sizeof($all);
// 循环
for ($i = 0; $i < $size; $i = $i + 1) {
  $item = $all[$i];
  ?>

  <div>
    菜品：
    <?php echo $item['dish_name']; ?>
    价格：
    <?php echo $item['price']; ?>
    <img src="<?php echo $item['dish_name'] . '.' . $item['img_ext_name']; ?>" />
  </div>

<?php

}
?>